package com.sinosoft.brokerchannel.base.conf;

import com.sinosoft.brokerchannel.base.handler.ViewHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

/**
 * @需求名称: Web配置类
 * @类描述: spring boot web配置类，自定义配置信息
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
    @Bean
    public ViewHandler viewHandler() {
        return new ViewHandler();
    }

    /**
     * 添加返回值拦截器，实现返回数据的拦截处理
     */
    @Override
    public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
        returnValueHandlers.add(this.viewHandler());
    }

    /**
     * 添加视图控制器
     *
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //主页
        registry.addViewController("/").setViewName("home");
        //错误页面跳转
        registry.addViewController("/error").setViewName("error");
        //info页面
        registry.addViewController("/info").setViewName("info");
    }
}
